#include "shuttle_shield.h"

SHUTTLE_SHIELD::SHUTTLE_SHIELD(CASH *cash):QGraphicsItemGroup()
{
    this->cash = cash;

    init();
}

SHUTTLE_SHIELD::~SHUTTLE_SHIELD(){}

QRectF SHUTTLE_SHIELD::boundingRect() const
{
    return QRectF();
}

QPainterPath SHUTTLE_SHIELD::shape() const
{
    return QPainterPath();
}

void SHUTTLE_SHIELD::init()
{
    //top
    item_tl = new SHUTTLE_SHIELD_ITEM(TL, cash);
    this->addToGroup(item_tl);

    item_tc = new SHUTTLE_SHIELD_ITEM(TC, cash);
    this->addToGroup(item_tc);

    item_tr = new SHUTTLE_SHIELD_ITEM(TR, cash);
    this->addToGroup(item_tr);

    //down
    item_dl = new SHUTTLE_SHIELD_ITEM(DL, cash);
    this->addToGroup(item_dl);

    item_dc = new SHUTTLE_SHIELD_ITEM(DC, cash);
    this->addToGroup(item_dc);

    item_dr = new SHUTTLE_SHIELD_ITEM(DR, cash);
    this->addToGroup(item_dr);

    //full shield
    item_full = new SHUTTLE_SHIELD_ITEM(FULL, cash);
    this->addToGroup(item_full);


}

void SHUTTLE_SHIELD::damaged(QPointF point)
{

    //top center
    if(mapFromScene(point).x() > 74 && mapFromScene(point).x() < 175 &&
       mapFromScene(point).y() > 13 && mapFromScene(point).y() < 125)
    {
        qDebug() << "tc boom))";
        item_tc->blink();
    }

    //top left
    if(mapFromScene(point).x() > 15 && mapFromScene(point).x() < 74 &&
       mapFromScene(point).y() > 30 && mapFromScene(point).y() < 116)
    {
        qDebug() << "tl boom))";
        item_tl->blink();
    }


    //top right
    if(mapFromScene(point).x() > 175 && mapFromScene(point).x() < 235 &&
       mapFromScene(point).y() > 30 && mapFromScene(point).y() < 116)
    {
        qDebug() << "tr boom))";
        item_tr->blink();
    }

    //down center
    if(mapFromScene(point).x() > 74 && mapFromScene(point).x() < 175 &&
       mapFromScene(point).y() > 222 && mapFromScene(point).y() < 235)
    {
        qDebug() << "dc boom))";
        item_dc->blink();
    }

    //down left
    if(mapFromScene(point).x() > 15 && mapFromScene(point).x() < 74 &&
            mapFromScene(point).y() > 116 && mapFromScene(point).y() < 222)
    {
        qDebug() << "dl boom))";
        item_dl->blink();
    }

    //down right
    if(mapFromScene(point).x() > 175 && mapFromScene(point).x() < 235 &&
            mapFromScene(point).y() > 116 && mapFromScene(point).y() < 222)
    {
        qDebug() << "dr boom))";
        item_dr->blink();
    }
}

void SHUTTLE_SHIELD::destroyed()
{
    item_tl->blink();
    item_tc->blink();
    //item_tr->blink();
    //item_dl->blink();
    item_dc->blink();
    item_dr->blink();
}
